package com.sqsf.aop;

import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component
public class ServiceLogAspect {

    private static final Logger logger = LoggerFactory.getLogger(ServiceLogAspect.class);

    /**
     * 定义切入点：拦截com.sqsf.service包及其子包下的所有类的所有方法
     */
    @Before("execution(* com.sqsf.service..*.*(..))")
    public void beforeServiceMethod(JoinPoint joinPoint) {
        // 获取目标类名
        String className = joinPoint.getTarget().getClass().getSimpleName();
        // 获取方法名
        String methodName = joinPoint.getSignature().getName();
        // 记录日志
        logger.info("执行了 {}.{} 操作", className, methodName);
    }
}